package com.itheima.ticket.ticket02;
/*
第一种解决方案
同步
 */
public class Ticket implements Runnable{
  private int ticket=100;
  private Object obj= new Object();

    @Override
    public void run() {
       while (true){
           //人有操作  耗时间
            //锁对象 必须 唯一
           synchronized (obj) {
               if(ticket>0){
                   try {
                       Thread.sleep(10);
                   } catch (InterruptedException e) {
                       e.printStackTrace();
                   }

                   System.out.println(Thread.currentThread().getName()+"正在卖"+ticket+"张票");
                   ticket--;
               }else {
                   break;
               }
           }

       }
    }
}
